load("data_regression.rda")

library(plm)

# HU, Table 1 #-----------------------------------------------------------------------------------#
jd.hu <- subset(jd.df, year < 2015)
jd.hu$hu <- ifelse(jd.hu$year == 2012, 1, 0)
table(jd.hu$hu)

f1.h <- plm(trust.hi ~ dic2 + hu, data = jd.hu,
            index = c("city", "year"), model = "within")
f1.l <- plm(trust.lo ~ dic2 + hu, data = jd.hu,
            index = c("city", "year"), model = "within")
summary(f1.h); summary(f1.l)

f2.h <- plm(trust.hi ~ dic2 + hu + 
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.hu,
            index = c("city", "year"), model = "within")
f2.l <- plm(trust.lo ~ dic2 + hu +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.hu,
            index = c("city", "year"), model = "within")
summary(f2.h); summary(f2.l)

stargazer::stargazer(f1.h, f1.l, f2.h, f2.l,
          type = "html", out = "Tab1_1027.htm")


# Tiger, Table 2 #--------------------------------------------------------------------------------#
t1.h <- plm(trust.hi ~ xi + dic2 + prov.head + 
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
t1.l <- plm(trust.lo ~ xi + dic2 + prov.head +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
summary(t1.h); summary(t1.l)

t2.h <- plm(trust.hi ~ xi + dic2 + prov.hddp +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df,
            index = c("city", "year"), model = "within")
t2.l <- plm(trust.lo ~ xi + dic2 + prov.hddp +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df,
            index = c("city", "year"), model = "within")
summary(t2.h); summary(t2.l)

t3.h <- plm(trust.hi ~ xi + dic2 + city.head + 
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
t3.l <- plm(trust.lo ~ xi + dic2 + city.head +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
summary(t3.h); summary(t3.l)

t6.h <- plm(trust.hi ~ xi + dic2 + t1 + 
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
t6.l <- plm(trust.lo ~ xi + dic2 + t1 +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
summary(t6.h); summary(t6.l)

t7.h <- plm(trust.hi ~ xi*dic2 + 
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
t7.l <- plm(trust.lo ~ xi*dic2 +
              perf + dw.state + ccp + sex + hukou + edu.l + inc.lo, data = jd.df, 
            index = c("city", "year"), model = "within")
summary(t7.h); summary(t7.l)

stargazer::stargazer(x1.h, x1.l, x2.h, x2.l, x3.h, x3.l, t6.h, t6.l, t7.h, t7.l,
          type = "html", out = "Tab2_1027.htm")
